import { useEffect } from "react";

import { useTokenStore } from "~/modules/auth/store/use-token";

interface Props {
  token: string;
  user?: any;
}

const SetTokenByGarfish = (props: Props) => {
  const { setToken } = useTokenStore();
  const handleToken = (token: string) => {
    setToken(token);
  };
  useEffect(() => {
    setToken(props?.token || "");
    (window as any)?.Garfish?.channel?.on("_token", handleToken);
    return () => {
      (window as any)?.Garfish?.channel?.removeListener("_token", handleToken);
    };
  }, []);
  return null;
};
export default SetTokenByGarfish;
